<template>
  <div class="news-index">
    <!-- 头部背景图 -->
    <el-image class="news-bg" :src="locale == 'en-US' ? enNewsBg : zhNewsBg" lazy fit="contain" :alt="`${$t('platform')}`"></el-image>
    <div class="container">
      <!-- 分类名称 -->
      <div class="category-name margin-t50">
        <span>{{ $t("industryNews") }}</span>
        <a class="more-article" :href="`/news-list/1`" :title="`${$t('industryNews')}`">
          <span>{{ $t("viewMore") }}</span>
          <i class="arrow el-icon-arrow-right"></i>
        </a>
      </div>
      <!-- 图文列表 -->
      <section class="article-list">
        <a class="article-item" v-for="item in industryList" :key="item.id" :href="`/news-detail/${item.id}`" :title="item.title">
          <div class="pic">
            <el-image class="info-img" fit="cover" :src="item.imageUrl" lazy :alt="item.title"></el-image>
          </div>
          <div class="info-bottom">
            <div class="article-title">{{ item.title }}</div>
            <div class="release-time">
              <span>{{ item.releaseTime }}</span>
              <div class="button-next">
                <i class="arrow el-icon-arrow-right"></i>
              </div>
            </div>
          </div>
        </a>
      </section>
      <!-- 分类名称 -->
      <div class="category-name margin-t50">
        <span>{{ $t("transactionCase") }}</span>
        <a class="more-article" :href="`/news-list/2`" :title="`${$t('transactionCase')}`">
          <span>{{ $t("viewMore") }}</span>
          <i class="arrow el-icon-arrow-right"></i>
        </a>
      </div>
      <!-- 图文列表 -->
      <section class="article-list margin-b">
        <a class="article-item" v-for="item in transactionCaseList" :key="item.id" :href="`/news-detail/${item.id}`" :title="item.title">
          <div class="pic">
            <el-image class="info-img" fit="cover" :src="item.imageUrl" lazy :alt="item.title"></el-image>
          </div>
          <div class="info-bottom">
            <div class="article-title">{{ item.title }}</div>
            <div class="release-time">
              <span>{{ item.releaseTime }}</span>
              <div class="button-next">
                <i class="arrow el-icon-arrow-right"></i>
              </div>
            </div>
          </div>
        </a>
      </section>
    </div>
    <!-- 侧边栏服务 -->
    <Dangling v-if="locale == 'zh-CN'" />
    <!-- WhatsApp -->
    <!-- <WhatsApp v-if="locale == 'en-US'" /> -->
    <!-- 在线客服 -->
    <Connect />
  </div>
</template>

<script>
import { mapState } from "vuex"
export default {
  name: "NewsIndex",
  layout: "Layout",
  components: {},
  data() {
    return {
      zhNewsBg: "https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/news-bg.png",
      enNewsBg: "https://yunlian-oss-product.oss-cn-hangzhou.aliyuncs.com/website/news-bg-en.png"
    }
  },
  head() {
    return {
      title: this.$i18n.t("headTitle"),
      meta: [
        {
          hid: "keywords",
          name: "keywords",
          content: this.$i18n.t("haeaKeyContent")
        },
        {
          hid: "description",
          name: "description",
          content: this.$i18n.t("haeaDecContent")
        }
      ]
    }
  },
  async asyncData({ app, query }) {
    let industryForm = {
        pageNo: 1,
        pageSize: 4,
        sort: "id desc"
      },
      transactionCaseForm = {
        pageNo: 1,
        pageSize: 8,
        sort: "id desc"
      },
      industryList = [],
      transactionCaseList = []
    try {
      let { data: industryData } = await app.$api.articleList({ ...industryForm, search: { categoryName: "1" } })
      industryList = industryData.list
      let { data: transactionCaseData } = await app.$api.articleList({ ...transactionCaseForm, search: { categoryName: "2" } })
      transactionCaseList = transactionCaseData.list
    } catch (error) {
      console.log(error)
    }
    return {
      industryList,
      transactionCaseList
    }
  },
  props: {},
  computed: { ...mapState(["locale"]) },
  async mounted() {
    this.getPoint()
  },
  methods: {
    async getPoint() {
      let params = await this.$optionPoint.sendUrl(window, navigator, document)
      this.$api.burySave({ ...params }).then((res) => {})
    }
  },
  watch: {}
}
</script>

<style lang="scss" scoped>
.news-index {
  .news-bg {
    width: 100%;
  }
  .category-name {
    display: flex;
    align-items: center;
    justify-content: space-between;
    span {
      font-size: 22px;
      font-weight: 600;
      color: #333;
      line-height: 24px;
    }
    .more-article {
      display: flex;
      align-items: center;
      span {
        font-family: PingFangSC, PingFang SC;
        font-weight: 400;
        font-size: 16px;
        color: #333;
      }
      .arrow {
        font-size: 18px;
        color: #333;
      }
    }
  }
  .margin-t50 {
    margin-top: 50px;
  }
  .margin-t50 {
    margin-top: 30px;
  }
  .article-list {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    margin-top: 20px;
    .article-item {
      width: 23.8%;
      height: 100%;
      margin-bottom: 20px;
      .pic {
        display: block;
        overflow: hidden;
        width: 100%;
        .info-img {
          width: 100%;
          height: 184px;
          display: block;
          transition: all 0.3s ease 0s;
          -webkit-transition: all 0.3s ease 0s;
          &:hover {
            transform: scale(1.05);
            -webkit-transform: scale(1.05);
          }
        }
      }
      .info-bottom {
        width: 100%;
        height: 116px;
        background: #f6f7f9;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        padding: 10px;
        box-sizing: border-box;
        .article-title {
          font-family: PingFangSC, PingFang SC;
          font-weight: 500;
          font-size: 18px;
          line-height: 24px;
          color: #333;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2;
          text-overflow: ellipsis;
          overflow: hidden;
        }
        .release-time {
          display: flex;
          align-items: center;
          justify-content: space-between;
          span {
            font-family: PingFangSC, PingFang SC;
            color: #6e6e6e;
            font-size: 14px;
          }
          .button-next {
            width: 20px;
            height: 20px;
            color: #cbe6ff;
            border: 2px solid #cbe6ff;
            border-radius: 50%;
            position: relative;
            &:hover {
              border-color: #183883;
              color: #183883;
            }
            .arrow {
              position: absolute;
              left: 50%;
              top: 50%;
              margin-top: -7px;
              margin-left: -6px;
              font-size: 14px;
              font-weight: 600;
              color: inherit;
            }
          }
        }
      }
      &:last-child:nth-child(4n - 1) {
        margin-right: calc(24% + 4% / 3);
      }
      &:last-child:nth-child(4n - 2) {
        margin-right: calc(48% + 8% / 3);
      }
    }
  }
  .margin-b {
    margin-bottom: 50px;
  }
}
</style>
